﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZDT.Task.Entity;
using ZDT.Common;
using ZDT.UI.Web;
using System.Threading;

namespace ZDT.Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();        
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(() =>
            {
                ZDT.UI.Frm.CheckCodeForm form1 = new ZDT.UI.Frm.CheckCodeForm();
                form1.Url = @"http://www.baidu.com/img/baidu_jgylogo3.gif?v=04876784.gif";
                form1.ShowDialog();
            });
            thread.Start();
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            WebBrowseTask btask = new WebBrowseTask();
            var stg = btask.Setting = new Task.TPurview.PurviewSetting();
            stg.BaseUrl = "http://www.baidu.com/";
            stg.Wait = 5;
            stg.LoginUrlFmt = "http://www.baidu.com/login";
            stg.LoginWait = 5;
            stg.AddUrlFmt = "http://www.baidu.com/add";
            stg.AddWait = 5;
            stg.RefreshUrlFmt = "http://www.baidu.com/refresh";
            stg.RefreshWait = 5;
            stg.NextWait = 10;
            stg.RefScripts = new List<string>()
            {
                "1.js"
                ,"2.js"
                ,"3.js"
            };
            stg.UrlScripts = new SDictionary<string, string> { 
                { "http://www.baidu.com/login", "login.js" } 
                ,{ "http://www.baidu.com/add", "add.js" } 
                ,{ "http://www.baidu.com/refresh", "refresh.js" } 
            };
            var data = btask.Data = new List<Task.TPurview.PurviewData>();
            var dataItem = new Task.TPurview.PurviewData();
            dataItem.Id = "1";
            dataItem.Data = new SDictionary<string, string> { 
                { "title", "标题1" } 
                ,{ "message", "消息1" } 
                ,{ "datetime", "2014-01-01" } 
            };
            data.Add(dataItem);
            dataItem = new Task.TPurview.PurviewData();
            dataItem.Id = "2";
            dataItem.Data = new SDictionary<string, string> { 
                { "title", "标题2" } 
                ,{ "message", "消息2" } 
                ,{ "datetime", "2014-01-01" } 
            };
            data.Add(dataItem);

            btask.WebBrowser = this.myWebBrowser1;
            btask.Start();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string source = ZDT.Http.Url.GetSource(@"http://xm.ganji.com/fang5/", GlobalParas.WebCode.auto, "");
            var r = ZDT.Text.StringMatch.RHttpPath.Match("http://www.baidu.com/123/11ab?1=21&124312");

            GatherInfo info = new GatherInfo();
            info.RootUrl = "http://www.baidu.com";
            info.BaseUrl = "http://www.baidu.com/xm/list.php?";
            info.LoginInfo = new LoginInfo();
            info.ListPageInfo = new ListPageInfo();
            info.ListPageInfo.UrlRule = new GatherRule();
            info.ListPageInfo.DetailRule = new GatherRule();
            info.DetailInfo = new DetailInfo();
            info.DetailInfo.BaseRule = new GatherRule();
            info.DetailInfo.ImgRule = new GatherRule();
            info.DetailInfo.ImgItemRule = new GatherRule();
            info.DetailInfo.Rules = new SDictionary<string, GatherRule>();
            info.DetailInfo.Rules.Add("Caption", new GatherRule());
            info.DetailInfo.Rules.Add("Desc", new GatherRule());

            Common.X2S.ObjToFile(info, "GatherRule.xml");
            var info2 = Common.X2S.FileToObj<GatherInfo>("GatherRule.xml");
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }
    } 
}
